package org.linlinjava.litemall.admin.controller;

import javax.validation.constraints.NotNull;

import org.linlinjava.litemall.admin.beans.annotation.LogAnno;
import org.linlinjava.litemall.admin.beans.annotation.LoginAdminShopId;
import org.linlinjava.litemall.admin.beans.dto.SubscribeDto;
import org.linlinjava.litemall.admin.service.SubscribeService;
import org.linlinjava.litemall.core.validator.Order;
import org.linlinjava.litemall.core.validator.Sort;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 管理订阅控制器
 *
 * @author yliyun
 * @description：TODO
 * @date 2022/09/14
 */

@RestController
@RequestMapping("/admin/subscribe")
public class AdminSubscribeController {

    /**
     * 订阅服务
     */
    @Autowired
    private SubscribeService subscribeService;

    /**
     * 列表
     *
     * @param name  名字
     * @param page  页面
     * @param limit 限制
     * @param sort  排序
     * @param order 订单
     * @return {@link Object}
     */
    @GetMapping("/list")
    @LogAnno
    public Object list(String name,
                       @RequestParam(defaultValue = "1") Integer page,
                       @RequestParam(defaultValue = "10") Integer limit,
                       @Sort @RequestParam(defaultValue = "add_time") String sort,
                       @Order @RequestParam(defaultValue = "desc") String order) {
        return subscribeService.querySelective(name, page, limit, sort, order);
    }

    /**
     * 创建
     *
     * @param dto dto
     * @return {@link Object}
     */
    @PostMapping("/create")
    @LogAnno
    public Object create(@RequestBody @Validated SubscribeDto dto) {
        return subscribeService.add(dto);
    }

    /**
     * 删除
     *
     * @param id id
     * @return {@link Object}
     */
    @DeleteMapping("/delete")
    @LogAnno
    public Object delete(@NotNull Integer id) {
        return subscribeService.delete(id);
    }

    /**
     * 更新
     *
     * @param dto dto
     * @return {@link Object}
     */
    @PutMapping("/update")
    @LogAnno
    public Object update(@RequestBody @Validated SubscribeDto dto) {
        return subscribeService.update(dto);
    }

    /**
     * 读
     *
     * @param id id
     * @return {@link Object}
     */
    @GetMapping("/read")
    @LogAnno
    public Object read(@NotNull Integer id) {
        return subscribeService.read(id);
    }

    /**
     * 用户
     *
     * @param name    名字
     * @param goodsId 商品id
     * @param shopId  商店id
     * @param page    页面
     * @param limit   限制
     * @param sort    排序
     * @param order   订单
     * @return {@link Object}
     */
    @GetMapping("/users")
    @LogAnno
    public Object users(
            String name,
            Integer goodsId,
            @LoginAdminShopId Integer shopId,
            @RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "10") Integer limit,
            @Sort @RequestParam(defaultValue = "add_time") String sort,
            @Order @RequestParam(defaultValue = "desc") String order) {
        return subscribeService.subscribeUserList(name, goodsId, shopId, page, limit, sort, order);
    }

    /**
     * 用户详细信息
     *
     * @param id id
     * @return {@link Object}
     */
    @GetMapping("/user/detail")
    @LogAnno
    public Object userDetail(@NotNull Integer id) {
        return subscribeService.subscribeUserDetail(id);
    }
}

